package timing.ukulele.third.service.msg;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import timing.ukulele.data.third.data.msg.MessageKeyMappingFiledDTO;
import timing.ukulele.data.third.view.msg.MessageKeyMappingFiledVO;
import timing.ukulele.third.convertor.msg.MessageKeyMappingFiledConverter;
import timing.ukulele.third.mapper.msg.MessageKeyMappingFiledMapper;
import timing.ukulele.third.persistent.msg.MessageKeyMappingFiled;
import timing.ukulele.third.service.common.BaseOperatorService;
import java.util.List;

/**
 * 消息参数字段映射管理
 */
@Slf4j
@Service
@AllArgsConstructor
public class MessageKeyMappingFiledService extends BaseOperatorService<MessageKeyMappingFiledMapper, MessageKeyMappingFiled> {

    /**
     * 分页列表
     * @param dto
     * @return
     */
    public IPage<MessageKeyMappingFiledVO> pageList(MessageKeyMappingFiledDTO dto) {
        Page pageParam = new Page(dto.getCurrent(), dto.getPageSize());
        Page page = this.lambdaQuery()
                .like(StrUtil.isNotBlank(dto.getMappingFiled()), MessageKeyMappingFiled::getMappingFiled, dto.getMappingFiled())
                .page(pageParam);
        List list = MessageKeyMappingFiledConverter.INSTANCE.p2vList(page.getRecords());
        page.setRecords(list);
        return page;
    }

    /**
     * 获取全部列表
     * @return
     */
    public List<MessageKeyMappingFiledVO> getAllList() {
        List<MessageKeyMappingFiled> list = this.lambdaQuery().eq(MessageKeyMappingFiled::getDeleted, Boolean.FALSE).list();
        return MessageKeyMappingFiledConverter.INSTANCE.p2vList(list);
    }

    /**
     * 根据字段集合获取数据
     * @param filedList
     * @return
     */
    public List<MessageKeyMappingFiled> getByFiledList(List<String> filedList) {
       return this.lambdaQuery().in(MessageKeyMappingFiled::getMappingFiled, filedList).list();
    }

}
